package com.week2.day04.teamFight;

import java.util.Comparator;
import java.util.Random;

public class Hero implements Fightable, Team {
    private int hp;
    private int damage;

    public Hero() {
        Random random = new Random();
        hp = random.nextInt(40) + 80;
        damage = random.nextInt(10) + 20;
    }

    public Hero(int hp, int damage) {
        this.hp = hp;
        this.damage = damage;
    }

    public int getHp() {
        return hp;
    }

    public void setHp(int hp) {
        this.hp = hp;
    }

    public int getDamage() {
        return damage;
    }

    public void setDamage(int damage) {
        this.damage = damage;
    }

    @Override
    public boolean isAlive() {
        return hp > 0;
    }

    @Override
    public void attack(Fightable enemy) {
        if (isAlive()) {
            enemy.injured(damage);
        }
    }

    @Override
    public void injured(int damage) {
        hp -= damage;
    }

    @Override
    public Hero[] teamUp(int num) {
        Hero[] heroes = new Hero[num];
        for (int i = 0; i < num; i++) {
            heroes[i] = new Hero();
        }
        return heroes;
    }

    @Override
    public String toString() {
        return "Hero{" +
                "hp=" + hp +
                '}';
    }
}
